#pragma once

#include <functional>
#include <string>

class Task
{
    using func_t = std::function<std::string(int,int,char)>;
public:
    Task()
    {}
    Task(int x,int y, char op, func_t func)
        :_x(x), _y(y), _op(op), _callback(func)
    {}

    std::string operator()()
    {
        return _callback(_x,_y,_op);
    }

    std::string toString()
    {
        char buffer[64];
        snprintf(buffer, sizeof buffer, "%d %c %d = ?", _x, _op, _y);
        return buffer;
    }
private:
    int _x;
    int _y;
    char _op;
    func_t _callback;
};



std::string mymath(int x,int y,char op)
{
    int result = 0;
    switch(op)
    {
        case '+':
        result = x + y;
        break;

        case '-':
        result = x - y;
        break;

        case '*':
        result = x * y;
        break;

        case '/':
        if(y == 0)
        {
            return std::string("div 0 错误");
        }
        else
        {
            result = x / y;
        }
        break;

        case '%':
        if(y == 0)
        {
            return std::string("mod 0 错误");
        }
        else
        {
            result = x % y;
        }
        break;

        default:
        return std::string("无法处理该操作符");
        break;
    }
    char buffer[64];
    snprintf(buffer,sizeof buffer,"%d %c %d = %d", x, op, y, result);
    return std::string(buffer);
}